﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using SqlserverHelper;
using System.Threading;

using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using OJ;
using DLLmySQL;

public partial class getDistPrd : System.Web.UI.Page
{
    public string strCnn = ConfigurationSettings.AppSettings["DataBaseString"];

    protected void Page_Load(object sender, EventArgs e)
    {
        string user_identity = "";
        if (Request.Form["user_identity"] != null && Request.Form["user_identity"].ToString().Trim() != "")
        {
            user_identity = Request.Form["user_identity"].ToString();
        }

        string stResult = f_getDistPrd(user_identity);
        Response.Write(stResult);
    }

    public string f_getDistPrd(string user_identity)
    {
        Define.retPrdList ret = new Define.retPrdList();


        try
        {
            string strWhere = "";
            if(user_identity != "")
            {
                strWhere = " and user_identity = '" + user_identity + "'";
            }

            string strQuery = "select id,prd_code,prd_name from dsh_prd where 1=1 " + strWhere;
            DataTable DT = CmySQL.GetDataTbale(strCnn, strQuery);

            if (DT != null && DT.Rows.Count > 0)
            {
                List<Define.PrdList> L = new List<Define.PrdList>();
                Define.PrdList r1 = new Define.PrdList();

                r1.id = "";
                r1.prd_code = "";
                r1.prd_name = "全部";

                L.Add(r1); 
                for (int i = 0; i < DT.Rows.Count; i++)
                {
                    Define.PrdList r = new Define.PrdList();

                    r.id = DT.Rows[i][0].ToString().Trim();
                    r.prd_code = DT.Rows[i][1].ToString().Trim();
                    r.prd_name = DT.Rows[i][2].ToString().Trim();


                    L.Add(r);
                }
                ret.code = 200;
                ret.msg = "success";
                ret.data = L;
            }
            else
            {
                ret.code = 200;
                ret.msg = "无数据!";
                ret.data = null;
            }
        }
        catch
        {
            ret.code = 20000;
            ret.msg = "服务不可用";
            ret.data = null;
        }

        return Ojson.ObjectToJson(ret);
    }
}